package com.example.mybatisplus.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.mybatisplus.pojo.One;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface OneMapper extends BaseMapper<One> {
    @Results(id = "oneResultMap",value = {
            @Result(id = true,column ="one_id",property = "id"),
            @Result(column ="one_name",property = "oneName"),
            @Result(column = "one_create_time",property = "oneCreateTime"),
            @Result(column = "other_id",property = "other",
                    one =@org.apache.ibatis.annotations.One(select = "com.example.mybatisplus.mapper.OtherMapper.selectById",fetchType = FetchType.LAZY)),
            //这里的one_id是结果集里的，将one_id的数据传入selectByOneId(oneId)中进行查询出one_id的所有more
            @Result(column = "one_id",property = "moreList",
                    many = @Many(select = "com.example.mybatisplus.mapper.MoreMapper.selectByOneId",fetchType = FetchType.DEFAULT))
    })
    @Select("select * from one where one_id=#{id}")
    public One selectById(Long id);


    @Insert("insert one values(#{et.id},#{et.oneName},#{et.oneAge},#{et.oneCreateTime},#{et.other.id})")
    public int insert(@Param(Constants.ENTITY) com.example.mybatisplus.pojo.One one);
}
